<?php


namespace App\Api\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;


class PromotionBargain extends Model
{
    use HasFactory;
    protected $guarded = [];
    protected $table = 'cmc_promotion_bargain';

    /**
     * 查询有效时间内数据 并获取指定字段
     * @param $field
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public static function BargainLists($field){

        return self::query()
            ->where('start_time','<' ,date('Y-m-d H:i:s',time()))
            ->where('end_time','>' ,date('Y-m-d H:i:s',time()))
            ->get($field);
    }

    /**
     * 查询砍价活动
     * @param $bargain_id
     * @param $field
     * @return array
     */
    public static function bargainInfo($bargainId,$field)
    {
        return self::query()->where('id',$bargainId)->first($field)->toArray();
    }

    /**
     * 根基id查询 并获取指定字段
     * @param $bargain_id
     * @param $field
     * @return mixed
     */
    public static function field($bargainId,$field)
    {
        return self::query()->where('id',$bargainId)->value($field);
    }


}
